package com.asset.dispoal.business.mediation;

import com.asset.dispoal.business.mediation.api.MediationService;
import com.asset.dispoal.business.mediation.dto.CalculateRateRequest;
import com.asset.dispoal.business.mediation.dto.CalculateRateResponse;
import com.asset.dispoal.business.mediation.dto.MediationRequest;
import com.asset.dispoal.business.mediation.dto.MediationResponse;
import com.asset.dispoal.business.mediation.dto.ReduceDtailInfoResponse;
import com.asset.dispoal.business.mediation.dto.ReduceLogsResponse;
import com.asset.dispoal.business.mediation.dto.ReducePresetResponse;
import com.asset.dispoal.business.mediation.dto.SaveReduceInfoRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import tech.mhuang.pacebox.core.util.StringUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @author: yf
 * @date: 2022-08-23
 */
@Slf4j
@RestController
@RequestMapping("business/mediation")
@Api(value = "调解管理", tags = "调解管理")
public class MediationController {

    @Autowired
    private MediationService mediationService;

    @PostMapping("queryBorrowerCaseByPage")
    @ApiOperation(value = "调解管理列表接口", notes = "调解管理列表接口")
    public Result<PageVO<MediationResponse>> queryBorrowerCaseByPage(@RequestBody MediationRequest mediationRequest) {
        return mediationService.queryBorrowerCaseByPage(mediationRequest);
    }

    @GetMapping("reducePreset")
    @ApiOperation(value = "减免预设息接口", notes = "减免预设息接口")
    public Result<ReducePresetResponse> reducePreset(@ApiParam(value = "案件id") String caseId) {
        return mediationService.getAgreeMentCaseListByCaseId(caseId);
    }

    @PostMapping("reduceSave")
    @ApiOperation(value = "減免預設信息保存接口", notes = "將合同, 減免方式，分期數進行保存")
    public Result reduceSave(SaveReduceInfoRequest request) {
        return mediationService.save(request);
    }

    @GetMapping("reduceLogList")
    @ApiOperation(value = "减免日志列表", notes = "减免日志列表")
    public Result<List<ReduceLogsResponse>> list(String caseId) {
        return mediationService.getLogList(caseId);
    }

    @GetMapping("reduceDetailInfo")
    @ApiOperation(value = "减免详细信息", notes = "减免详细信息")
    public Result<ReduceDtailInfoResponse> detailInfo(String id) {
        if (StringUtil.isEmpty(id)) {
            return Result.faild("id不能为空");
        }
        return mediationService.getReduceDetailInfo(id);
    }

    @PostMapping("calculate")
    @ApiOperation(value = "利率减免计算接口", notes = "利率减免计算接口")
    public Result<CalculateRateResponse> calculate(@RequestBody CalculateRateRequest request) {
        return mediationService.calculate(request);
    }

    @PostMapping("reconcile")
    @ApiOperation(value = "和解接口", notes = "详情和解按钮使用接口")
    public Result reconcile(List<MultipartFile> reconcileFiles, String caseId) {
        //TODO 待更改和解逻辑， 在减免预设信息保存的时候才上传减免文件
        mediationService.reconcile(reconcileFiles, caseId);
        return Result.ok();
    }

    @GetMapping("getOneReduceDetail")
    @ApiOperation(value = "处置管理减免预设信息接口", notes = "减免详细信息")
    public Result<ReduceDtailInfoResponse> getOneReduceDetail(String caseId) {
        if (StringUtil.isEmpty(caseId)) {
            return Result.faild("案件id不能为空");
        }
        return mediationService.getOneReduceDetail(caseId);
    }

}
